package com.rfsp.common.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class HttpUtil {
	private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);

	public static String post(String url, String jsonData) {
		HttpRequest request = HttpRequest.post(url);
		request.header("Content-Type", "application/json");
		request.body(jsonData);
		HttpResponse response = request.execute();
		return response.body();
	}

	public static String get(String url) {
		HttpRequest request = HttpRequest.get(url);
		HttpResponse response = request.execute();
		return response.body();
	}

	public static String post(String url, Map<String, String> params) {
		// 构建表单POST请求
		HttpRequest request = HttpRequest.post(url);
		request.header("Content-Type", "application/x-www-form-urlencoded"); // 表单类型的Content-Type
		request.formStr(params);
		HttpResponse response = request.execute();
		return response.body();
	}

	public static void main(String[] args) {
		String responseBody = HttpUtil.get("https://www.crcrfsp.org.cn/platform_introduce.do");
		logger.info(responseBody);
	}
}
